#include "ParticleSpringGenerator.h"


namespace SimPhy
{


ParticleSpringGenerator::ParticleSpringGenerator(Particle *other, real springConstant, real restLenght)
    : m_other(other), m_springConstant(springConstant), m_restLenght(restLenght)
{
}

ParticleSpringGenerator::~ParticleSpringGenerator()
{
}

void ParticleSpringGenerator::updateForce(Particle *particle, real timeStep)
{
    Vector3D force;

    // Calculate the vector from the "other" particle to the "particle" particle
    force=particle->getPosition()-m_other->getPosition();

    //Calculate the magnitude of the force
    real magnitude =-m_springConstant*(force.lenght()-m_restLenght);

    //calculate the final force and apply it
    force.normalize();
    force=magnitude*force;

    particle->addForce(force);
}


}
